<template>
	<statusBarVue title="我的收藏" :isShowBar="true" :isShowLeft="true" :isMyBgi="true" />
	<view class="favorites-page" :style="pageHaveBarStyle">
		<view class="favorites-page-group" v-if="favoriteList.lengths">
			<view class="favorites-page-list">
				<!-- <uni-list :border="false">
					<uni-list-item v-for="(item,index) in favoriteList" showArrow :title="item.name" />
				</uni-list> -->
				<uni-swipe-action ref="swipeAction">
					<uni-swipe-action-item :left-options="optionsLeft" @click="handleDelFavorite(v.id)"
						class="favorites-page-item content-box" v-for="(v,i) in favoriteList"
						:key="'favorites-list-'+index">
						<view class="content-text" @click="handlefavorite(v.ref_topic)">
							<text>{{ v.name }} </text>
							<uni-icons type="right"></uni-icons>
						</view>
					</uni-swipe-action-item>
				</uni-swipe-action>
			</view>
		</view>
		
		<emptyVue v-else />
	</view>
</template>

<script>
	import statusBarVue from '@/components/statusBar.vue';
	import emptyVue from '@/components/empty.vue';
	import {
		publics
	} from '@/mixins/publics.js';

	import {
		getCheckFavoriteList,
		postDelFavorite
	} from "@/utils/api"


	export default {
		mixins: [publics],
		components: {
			statusBarVue,
			emptyVue
		},
		data() {
			return {
				fid: '',
				next_ts: 1734818358,
				page: 1, // 当前页
				loadingMore: false,
				optionsLeft: [{
					text: '删除',
					style: {
						backgroundColor: '#ff3f3f'
					}
				}],
				favoriteList: []
			}
		},
		onShareAppMessage(){
			// 监听用户右上角的转发
		},
		onShareTimeline(){
			// 监听用户右上角的分享到朋友圈
		},
		onShow() {
			this.getCheckFavoriteListApi();
		},
		methods: {
			postDelFavoriteApi(code) {
				postDelFavorite(code).then(res => {
					this.getCheckFavoriteListApi();
				})
			},
			getCheckFavoriteListApi() {
				this.$refs.swipeAction.closeAll();
				getCheckFavoriteList().then(res => {
					if (res.code === 200) {
						this.favoriteList = res.data.favorites;
					}
				})
			},
			// 查看详情
			handlefavorite(topicId) {
				uni.navigateTo({
					url: `/homePages/topic/details?topicId=${topicId}`
				});
			},
			// 删除
			handleDelFavorite(id) {
				uni.showModal({
					title: '提示',
					content: '您确定要删除此收藏吗？',
					success: (res) => {
						if (res.confirm) {
							this.postDelFavoriteApi(id)
						}
					}
				});
			}
		}
	}
</script>


<style lang="scss">
	.favorites-page {
		position: fixed;
		left: 0;
		right: 0;
		z-index: 99;
		// background: linear-gradient(to bottom, transparent 0%, #F5F6FA 20%, #F5F6FA 100%);
		background-color: #f5f6fa;
		padding: 10px 0;

		.favorites-page-group {
			width: 94.67vw;
			margin: auto;
			height: 100%;
			background-color: #fff;

			.content-box {
				flex: 1;
				height: 44px;
				line-height: 44px;
				position: relative;
				background-color: #fff;
				border-bottom: 1px solid #f5f5f5;

				.content-text {
					font-size: 15px;
					display: flex;
					justify-content: space-between;
					align-items: center;
					padding: 0 12px;
				}
			}
		}
	}
</style>